<!-- Teacher_TrainDongTaiList.html -->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>培训frame</title>
    <link rel="stylesheet" href="../../css/api.css" />
	<link rel="stylesheet" href="../../css/mui.min.css"/>
	<link rel="stylesheet" href="../../css/base.css"/>
	<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
	<style type="text/css">
		.cell-right-div{
			width: 80px;
			float: right;
			text-align: right;
			line-height: 20px;
		}
		.cell-left-div{
			margin-right: 80px;
			white-space: nowrap;
			word-break: keep-all;
			overflow: hidden;
			text-overflow: ellipsis;
			line-height: 20px;
		}
		.train-cell{
			padding: 10px 10px;
		}
		.hot-news-title{
			padding: 10px;
			background: white;
			height: 40px;
		}
		.hot-news-title-img{
			width: 14px;
			position: relative;
			top: 2px;
		}
		.hot-news-title-span{
			line-height: 20px;
		}
		.hot-train-image{
			width: 120px;
			height: 74px;
			float: right;
			border-radius: 4px;
			background-image: url(../../image/course_placehoder.png);
		}
		.hot-train-title-div{

		}
		.hot-train-time{
			margin-top: 10px;
		}
	</style>
</head>
<body>
	<ul id="dong_tai_list" class="mui-table-view">
	</ul>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript">

	var dongtaiArr = new Array();//动态数据
	var page = 1;
	var rows = 10;
	var refreshCount = 0;
	apiready = function(){
	    SendBehaviorTrajectoriesNotifi('0', '培训新闻列表', '137');
	    loadNewData();
	    setRefreshHeader();
		setPullUpRefresh();
	}
	//加载动态数据
	function loadData(){
		var params = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjid'),
			page : page,
			rows : rows
		};
		cfnetppPOST(url_trainNews, params, true, function(data, status){
			if (status == 'success') {
				if (data.status == true) {
					var trends = data.data.trends;
					if (trends != undefined && trends != null && trends.constructor == Array) {
						refreshCount = trends.length;
						var oldCount = dongtaiArr.length;
						dongtaiArr = dongtaiArr.concat(trends);
						var dongTaiHtmlStr = '';
						for (var i = oldCount; i < dongtaiArr.length; i++) {
							var dongTaiData = dongtaiArr[i];
							dongTaiHtmlStr += dongTaiHtmlString(i, dongTaiData);
						}
						if (page == 1) {
							$('#dong_tai_list').html(dongTaiHtmlStr);
						}else{
							$('#dong_tai_list').append(dongTaiHtmlStr);
						}
						setupDongTaiClick();
					}
				}
			}else{
				if (page > 1) {
					page--;
					refreshCount = rows;
				}
			}
		});
	}
	//设置动态点击事件
	function setupDongTaiClick(){
		$('.dongtai-cell').unbind('click');
		$('.dongtai-cell').click(function(){
			var index = $(this).attr('index');
			var dongTaiData = dongtaiArr[parseInt(index)];
			api.openWin({useWKWebView:true,
			    name: 'Teacher_TrainDongTaiDetail',
			    url: 'Teacher_TrainDongTaiDetail.html',
			    pageParam: dongTaiData
			});
		});
	}
	//动态html
	//动态html
	function dongTaiHtmlString(index, data) {
		var imgurl = data.imgurl;
		if (imgurl == null || imgurl == '') {
			imgurl = '../../image/course_placehoder.png';
		}
		return '<li index="'+index+'" class="dongtai-cell mui-table-view-cell train-cell">'+
					'<img class="hot-train-image" src="'+imgurl+'">'+
					'<div class="hot-train-title-div">'+
						'<p class="base_black_grey base_content_font train-title">'+
							data.title+
						'</p>'+
						'<p class="base_grey base_tag_font hot-train-time">'+
							timeStringWithTimeStamp(data.ctime.toString())+
						'</p>'+
					'</div>'+
				'</li>';
	}
	function loadNewData(){
		page = 1;
		loadData();
	}
	function loadMoreData(){
		page++;
		loadData();
	}
	//下拉刷新
	function setRefreshHeader(){
		api.setRefreshHeaderInfo({
			visible : true,
			bgColor : '#ccc',
			textColor : '#fff',
			textDown : '下拉刷新...',
			textUp : '松开刷新...',
			showTime : true
		}, function(ret, err) {
			loadNewData();
		});
	}
	// 上拉加载
	function setPullUpRefresh(){
		api.addEventListener({
			name : 'scrolltobottom'
		}, function(ret, err) {
			if (refreshCount >= rows) {
				refreshCount = 0;
				loadMoreData();
			}
		});
	}
</script>
</html>